import { createApp } from 'vue'
import App from './App.vue'
import { APP_NAME } from './globals';

// 引入 elementPlus
import ElementPlus from 'element-plus';
import zhCn from 'element-plus/es/locale/lang/zh-cn';

import { renderWithQiankun, qiankunWindow } from 'vite-plugin-qiankun/dist/helper'

import globalComponents from '@/components/global'
console.log("🚀 ~ globalComponents:", globalComponents)

// 引入所有的公共样式
import '@/assets/styles/index.scss';

import router from './router'

const render = () => {
  return createApp(App)
  .use(ElementPlus, {
    locale: zhCn,
  })
  .use(globalComponents)
  .use(router)
}

let app: any;

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render().mount(`#${APP_NAME}`)
}else{
  renderWithQiankun({
    mount(props) {
      console.log(`【子】 [LiveCircle] 【子应用：${APP_NAME}】 <<< mount `);
      
      render().mount((props.container
        ? props.container.querySelector(`#${APP_NAME}`)
        : document.getElementById(APP_NAME)) as Element)
    },
    bootstrap() {
      console.log(`【子】 [LiveCircle] 【子应用：${APP_NAME}】 <<< bootstrap `);
    },
    update() {
      console.log(`【子】 [LiveCircle] 【子应用：${APP_NAME}】 <<< update `);
    },
    unmount() {
      console.log(`【子】 [LiveCircle] 【子应用：${APP_NAME}】 <<< unmount `);
      app?.unmount();
    }
  });
}